package service_sys

import (
	"wrblog-api-go/app/common/token"
	"wrblog-api-go/app/dao/dao_sys"
)

func GetRolesByUserId(userId int64) ([]string, error) {
	var roles []string
	if token.IsAdmin(userId) {
		roles = append(roles, "*")
	}
	sysRoles, err := dao_sys.GetRolesByUserId(userId)
	for _, item := range sysRoles {
		roles = append(roles, item.RoleKey)
	}
	return roles, err
}

func GetPermissionsByUserId(userId int64) ([]string, error) {
	var permissions []string
	if token.IsAdmin(userId) {
		permissions = append(permissions, "*:*:*")
	}
	sysMenus, err := dao_sys.GetPermissionsByUserId(userId)
	for _, item := range sysMenus {
		permissions = append(permissions, item.Perms)
	}
	return permissions, err
}
